//
//  ConnectionsController.h
//  SolarSeek
//
//  Created by Erick Fejta on 05/05/26.
//  Copyright 2005 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>

#ifdef _SOLARSEEK_NEW_

@interface ConnectionsController : NSObject {
	NSMutableDictionary *_handlers;
	NSMutableSet *_connections;
	Message *_messageNewServer,
			*_messageNewPeer;
}

- (PeerConnectionHandler *)connectToPeer:(Peer *)peer;
- (TransferConnectionHandler *)connectToTransfer:(Transfer *)transfer;

- (PeerConnectionHandler *)handlerForPeer:(Peer *)peer;
- (TransferConnectionHandler *)handlerForTransfer:(Transfer *)transfer;

- (void)sendMessage:(Message *)message toPeer:(Peer *)peer;
- (void)sendMessageToServer:(Message *)message;

- (Message *)messageNewFromServer;	//kv observable.
- (Message *)messageNewFromPeer;	//kv observable.
- (Peer *)peerWithMessageNew;
@end

@interface ConnectionHandler (Private )
- (BOOL)isAnswerable;	//can we answer his calls.
- (BOOL)isCallable;		//can he answer our calls.
- (void)setIsConnected:(BOOL)connected;
- (void)setIsFirewalled:(BOOL)firewalled;
- (void)setState:(int)state description:(NSString *)description;
- (void)addNeed:(NSString *)need;
- (void)removeNeed:(NSString *)need;
@end

@interface ConnectionHandler : NSObject {
	BOOL _connected;
	BOOL _known;
	BOOL _firewalled;
	KVMutableSet *_needs;
	int _state;
	NSString *_descirptionState;
}

- (BOOL)isConnected;

- (int)state;
- (NSString *)descriptionState;


- (BOOL)containsNeed:(NSString *)need;
- (KVMutableSet *)needs;
@end

@interface ConnectionHandler (Type)
- (NSString *)type;
@end

@interface PeerConnectionHandler : ConnectionHandler {
	Peer *peer;
	
}

- (id)initWithPeer:(Peer *)peer;

- (Peer *)peer;
- (NSString *)type;
@end


@interface TransferConnectionHandler : ConnectionHandler {
	Transfer *transfer;
}

- (id)initWithTransfer:(Transfer *)transfer;
- (Transfer *)transfer;
- (Peer *)peer;
- (NSString *)type;
@end

	
#endif